--function printf() --end --' Смотрим ли мы сейчас туда, куда нужно или нет? class "eva_state_mgr_direction" (property_evaluator) function eva_state_mgr_direction:__init(name, st) super (nil, name) self.st = st end function eva_state_mgr_direction:evaluate() --utils_data.debug_write("eva_state_mgr_direction:evaluate() start") -- Если мы идем в смарткавер if self.st.target_state == "smartcover" then --utils_data.debug_write("eva_state_mgr_direction:evaluate() end 1") return true end local sight_type = self.object:sight_params() if (self.st.look_dir) then if (look_object_type(self.object, self.st)) then self.st.look_dir.y = 0 end self.st.look_dir:normalize() if utils_data.vector_cmp_prec(sight_type.m_vector, self.st.look_dir, 0.01) ~= true then --utils_data.debug_write("eva_state_mgr_direction:evaluate() end 8") return false end --utils_data.debug_write("eva_state_mgr_direction:evaluate() end 9") self:callback() return true end -- Если задан объект на который смотреть if (self.st.look_object) then if not (sight_type.m_object) then --utils_data.debug_write("eva_state_mgr_direction:evaluate() end 2") return false end if (sight_type.m_object:id() ~= self.st.look_object) then --utils_data.debug_write("eva_state_mgr_direction:evaluate() end 3") return false end if (self.st.point_obj_dir ~= look_object_type(self.object, self.st)) then --utils_data.debug_write("eva_state_mgr_direction:evaluate() end 4") return false end --utils_data.debug_write("eva_state_mgr_direction:evaluate() end 5") self:callback() return true end -- Если задана позиция в которую смотреть if (self.st.look_position) then if (sight_type.m_sight_type == CSightParams.eSightTypeAnimationDirection) then self:callback() return true end local s = look_position_type(self.object, self.st) if (sight_type.m_sight_type ~= s) then --utils_data.debug_write("eva_state_mgr_direction:evaluate() end 6") return false end local dir = vec_sub(self.st.look_position, self.object:position()) if (look_object_type(self.object, self.st)) then dir.y = 0 end dir:normalize() if utils_data.vector_cmp_prec(sight_type.m_vector, dir, 0.01) ~= true then --utils_data.debug_write("eva_state_mgr_direction:evaluate() end 8") return false end --utils_data.debug_write("eva_state_mgr_direction:evaluate() end 9") self:callback() return true end -- Если не задано куда смотреть. -- И если мы до этого куда то смотрели if sight_type.m_object ~= nil then --utils_data.debug_write("eva_state_mgr_direction:evaluate() end 10") return false end --' Или если мы смотрели не так как надо if sight_type.m_sight_type ~= look_position_type(self.object, self.st) then --utils_data.debug_write("eva_state_mgr_direction:evaluate() end 11") return false end self:callback() --utils_data.debug_write("eva_state_mgr_direction:evaluate() end 12") return true end function eva_state_mgr_direction:callback() if self.st.callback and self.st.callback.turn_end_func then self.st.callback.turn_end_func(self.st.callback.obj) if self.st.callback ~= nil then self.st.callback.turn_end_func = nil end end end class "eva_state_mgr_direction_search" (property_evaluator) function eva_state_mgr_direction_search:__init(name, st) super (nil, name) self.st = st end function eva_state_mgr_direction_search:evaluate() if self.st.look_dir or self.st.look_position or self.st.look_object then return false end return true end --' Включаем поворот class "act_state_mgr_direction_turn" (action_base) function act_state_mgr_direction_turn:__init(name, st) super (nil, name) self.st = st end function act_state_mgr_direction_turn:initialize() --printf("turning object %s ",self.object:name()) action_base.initialize(self) self:turn() end function act_state_mgr_direction_turn:execute() action_base.execute(self) --' Нельзя дергать дирекшн сталкера когда он в смарткавере... self:turn() end function act_state_mgr_direction_turn:finalize() action_base.finalize(self) end function act_state_mgr_direction_turn:turn() turn(self.object,self.st,true) end function look_at_object(npc, st) local obj = db.storage[st.look_object] and db.storage[st.look_object].object or level.object_by_id(st.look_object) if (obj) then st.point_obj_dir = look_object_type(npc, st) if st.point_obj_dir == true then npc:set_sight(obj,true, false, false) else npc:set_sight(obj,true, true) end end end --' Включаем поворот в никуда class "act_state_mgr_direction_search" (action_base) function act_state_mgr_direction_search:__init(name, st) super (nil, name) self.st = st end function act_state_mgr_direction_search:initialize() action_base.initialize(self) --utils_data.debug_write("direction_search 1") --' Если принудительно задано тип смотрения if state_lib.states[self.st.target_state].direction and state_lib.states[self.st.target_state].direction == CSightParams.eSightTypeAnimationDirection then self.object:set_sight(CSightParams.eSightTypeAnimationDirection, false,false) else self.object:set_sight(look_position_type(self.object, self.st), nil, 0) end --utils_data.debug_write("direction_search 2") end function act_state_mgr_direction_search:execute() action_base.execute(self) end function act_state_mgr_direction_search:finalize() action_base.finalize(self) end local look_direction_states = { -- threat = true, threat_na = true, wait_na = true, guard_na = true, hide_na = true } function look_object_type(npc, st) --' Возвращает true если нужно смотреть по направлению --' false - нужно смотреть на объект if look_direction_states[st.target_state] == true then return true end return state_lib.states[st.target_state].animation ~= nil end function look_position_type(npc, st) if st == nil then return look.path_dir end if state_lib.states[st.target_state].direction then return state_lib.states[st.target_state].direction end if st.look_position or st.look_dir then return look.direction end --[[ if (state_lib.states[st.target_state].movement ~= move.stand) then return look.path_dir end return look.danger --]] return look.path_dir end function turn(npc, st,check) if (st.look_dir) then if (look_object_type(npc,st)) then st.look_dir.y = 0 end st.look_dir:normalize() npc:set_sight(look.direction, st.look_dir, true) elseif (st.look_object) then look_at_object(npc, st) elseif (st.look_position) then if (check) then if (state_lib.states[st.target_state].direction) then npc:set_sight(CSightParams.eSightTypeAnimationDirection, false,false) return end end local dir = vec_sub(st.look_position, npc:position()) if (look_object_type(npc,st)) then dir.y = 0 end dir:normalize() if utils_data.vector_cmp(dir, VEC_ZERO) then st.look_position = vector():set(npc:position().x + npc:direction().x,npc:position().y + npc:direction().y,npc:position().z + npc:direction().z) dir = npc:direction() end npc:set_sight(look.direction, dir, true) else end end